package ru.hh.school;

import static ru.hh.school.util.ResourceManager.message;

public class PrivateMessage {
    private final long id;
    private final String text;

    private final int recipientId;

    public PrivateMessage(long id, String text, int recipientId) {
        this.recipientId = recipientId;
        this.id = id;
        this.text = text;
    }

    public long getId() {
        return id;
    }

    public String getText() {
        return text;
    }

    public int getRecipientId() {
        return recipientId;
    }

    public String getMagicRepresentation() {
        return message("command.priv.magic", getId(), getText());
    }

    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        PrivateMessage that = (PrivateMessage) o;

        if (id != that.id) {
            return false;
        }
        if (recipientId != that.recipientId) {
            return false;
        }
        if (text != null ? !text.equals(that.text) : that.text != null) {
            return false;
        }

        return true;
    }

    public int hashCode() {
        int result = (int) (id ^ (id >>> 32));
        result = 31 * result + (text != null ? text.hashCode() : 0);
        result = 31 * result + recipientId;
        return result;
    }

    public String toString() {
        return "PrivateMessage{" +
                "id=" + id +
                ", text='" + text + '\'' +
                ", recipientId=" + recipientId +
                '}';
    }
}